Skip to content

fix: send createSession 201 only after the transaction commits - #1461

Merged
KaranUnique merged 238 commits into
Canopus-Labs:datafrom
ionfwsrijan:fix/1442-create-session-transaction
Aug 8, 2026
Merged

fix: send createSession 201 only after the transaction commits#1461
KaranUnique merged 238 commits into
Canopus-Labs:datafrom
ionfwsrijan:fix/1442-create-session-transaction

Conversation

@ionfwsrijan

Copy link
Copy Markdown
Contributor

Problem

createSession (backend/controllers/sessionController.js) runs all writes inside mongoSession.withTransaction(async () => { ... }), but:

  • Lines 95–98: res.status(201).json(...) is sent inside the callback — before Mongoose commits. If the commit subsequently fails (network error, replica-set failover, duplicate key on a concurrent write), the client already got a 201 + full session object while the transaction was rolled back: a phantom success.
  • Lines 39–57: validation failures return res.status(400) inside the callback. Mongoose's withTransaction commits based on the callback's return value, so returning an Express response object commits instead of aborting — the opposite of the code's obvious intent.

Fix

  • Validate before opening the transactionrole/experience/MAX_SESSIONS checks now run first and return 4xx from the outer handler, never from inside the callback.
  • Move res.* out of the callback — the callback returns the created session, and res.status(201).json(...) is sent only after withTransaction resolves (i.e. after commit).
  • The SESSION_LIMIT_REACHED throw is replaced by an early 400 return ahead of the transaction.
  • endSession() stays in finally, guarded for the pre-transaction validation paths.

Files changed

  • backend/controllers/sessionController.js — restructured createSession.
  • backend/tests/sessionController.create.transaction.unit.test.js — tests for 400s without starting a transaction, no 201 on commit failure, and 201 only after commit.

Testing

npx vitest run tests/sessionController.create.transaction.unit.test.js — 5/5 passing.

Closes #1442

PrishaJain64 and others added 30 commits August 2, 2026 16:54
…dmap

Integrated ai powered project roadmap
…-64423

fix: code quality and safety improvements
…-37396

fix: code quality and safety improvements
…ats-checker

feat: enhance AI Resume Analyzer with ATS compatibility insights
…ral-interview-coach

feat: implement AI Behavioral Interview Coach
…n-calendar

feat: add personalized interview preparation calendar
…uestion-collections

feat: add interview question bookmark collections page
…preparation-certificates

feat: add interview preparation achievement certificates page
anupamme and others added 20 commits August 5, 2026 06:09
Automated dependency upgrade by OrbisAI Security
…dency

[Bug]: Missing Dependency in useMemo within BookmarkCollections
roadmapRoutes.js defines the full roadmap API (CRUD + task toggle, protected,
rate-limited) but was never registered in server.js, so every frontend call
to /api/roadmaps* returned 404.

Mount the router at /api/roadmaps to match the frontend API_PATHS.ROADMAP
entries. Verified by booting the server: /api/roadmaps now returns 401
(auth required) instead of 404.
Addresses CodeRabbit review comment on PR Canopus-Labs#1248. Versions 9.0.2–9.0.4
include STARTTLS pre-TLS buffer discarding (RFC 3207 §6 capability
injection fix), correct TLS handshake over user-provided sockets, and
SMTP parsing/socket lifecycle hardening.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ci: add automated stale issue and PR workflow
…roadmap-routes

fix: mount roadmap routes so the Project Roadmap feature stops 404ing
…iew-preparation-snapshot

feat: add AI interview preparation snapshot
…alized-interview-preparation-tips

feat: add AI personalized interview preparation tips
…iew-preparation-milestone-calendar

feat: add AI interview preparation milestone calendar
…mastery-progress-bar

feat: add AI topic mastery progress bar
…iew-preparation-habit-tracker

feat: add AI interview preparation habit tracker
The success response and 4xx validation returns were issued inside the
withTransaction callback, so a 201 could reach the client before the commit
finished (phantom success on rollback), and returning res inside the callback
resolved it as a commit instead of an abort. Move validation ahead of the
transaction, return the created session from the callback, and send the
response only after withTransaction resolves.

Closes Canopus-Labs#1442
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 91102f84-6bd0-4a50-b739-99add7ad614f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@KaranUnique
KaranUnique changed the base branch from main to data August 8, 2026 05:21
@KaranUnique
KaranUnique merged commit a56ac6e into Canopus-Labs:data Aug 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

createSession sends the HTTP 201 response inside the withTransaction callback — before the transaction commits